-
-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(stub-deps): ability to stub dependencies for ComponentTester #89
base: master
Are you sure you want to change the base?
Conversation
…through <require>
One thing I didn't test properly was using it together with |
I see you've updated a bunch of karma/webpack related settings. I guess they are solely affecting the test setup for the repo itself right? If I'm going to check it out with a Require.js based CLI project would I need to adjust anything specific except installing your PRs aurelia-testing branch? |
@zewa666 Yes. I decided to sync this with our setup in other plugin repos 😛 |
in src folder:
Test: import { bootstrap } from 'aurelia-bootstrapper';
import { StageComponent } from "aurelia-testing";
describe('sample', () => {
it('should render without and with child', async () => {
let component;
let subComponent;
// First block, ignoring Child-component
component = await StageComponent
.withResources("parent-component")
.inView('<parent-component></parent-component>')
.ignoreDependencies('child-component');
await component.create(bootstrap);
subComponent = component.element as HTMLElement;
expect(subComponent.textContent!.trim()).toEqual('Parent');
expect(subComponent.textContent!.trim()).not.toContain('Child');
await component.dispose();
// Second block, keeping Child-component
component = await StageComponent
.withResources("parent-component")
.inView('<parent-component></parent-component>')
// .ignoreDependencies('child-component');
await component.create(bootstrap);
subComponent = component.element as HTMLElement;
expect(subComponent.textContent!.trim()).toContain('Child');
await component.dispose();
});
}); The first one passes, the second one doesn't. It seems like the recreation of the StageComponent still remembers that the ignoreDependencies as of before is active. Commenting out the first block makes the second part of the test pass. |
Another sideffect is if i do this // OLD
.withResources("parent-component")
// NEW
.withResources(["parent-component", "child-component"]) the ignoreDependencies doesn't work at all. Guess this is not intended right? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried this out with our SystemJS test suite and it works great.
I have a couple of suggestions:
Thanks @RomkeVdMeulen Co-Authored-By: bigopon <[email protected]>
Co-Authored-By: bigopon <[email protected]>
@RomkeVdMeulen Thanks for the suggestion, they are very nice. It would be great if you could help on documentation of this feature too. |
Sure thing. I'll go get started. |
This describes a new feature of aurelia-testing introduced by aurelia/testing#89
@RomkeVdMeulen could you share the test you were performing with SystemJS? Wonders me why it failed with requirejs as depicted above. |
@bigopon Thanks for including my suggestion to make the calls cumulative, but as it stands it won't work anymore: |
just as another side-note ... for RequireJS based projects ignoreDependencies accepts the relative path to |
@zewa666 Our project is huge so that won't be practical, but what I'm doing is basically no different from the tests in Edit: our project uses an alias for our src dir, rather than relative paths. Maybe that influences things? |
So attached please find a minimalistic example I've created with the latest CLI and RequireJS. Maybe you can spot the difference @RomkeVdMeulen Archive.zip |
@bigopon Could you take a look at @zewa666's sample code? It seems the second test, without ignored dependencies, isn't working well. I'm not sure why. Looks like the dependency is loaded, but something else is going wrong preventing the child component from rendering properly. If I dump the rendered HTML at the end of the test, it looks like this: <parent-component class="au-target" au-target-id="4">
Parent <child-component message.bind="'Child'" class="au-target" au-target-id="1"></child-component>
</parent-component> From the EDIT: Nevermind, I seem to be on the wrong path. If you switch the two tests, you get <parent-component class="au-target" au-target-id="4">
Parent <child-component message.bind="'Child'" class="au-target" au-target-id="2">
Child
</child-component>
</parent-component> when |
@RomkeVdMeulen @zewa666 Can you help change the configuration of dependencies to be ignored to absolute path? It's what loader will resolve to eventually. |
I'm not sure this has anything to do with the absolute path though @bigopon. It works the first time and is able to match the dependency. It's just on the second try it screws up. |
@@ -183,3 +184,39 @@ describe('Template dependency stubbing', () => { | |||
}); | |||
}); | |||
}); | |||
|
|||
fdescribe('sample', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing this is debug code?
Nice work! |
I'm trying to add some base tests for requirejs to make sure things run smoothly. For the same setup, i didn't get any issues with Webpack. |
@bigopon I can't build the latest version. I'm getting this error:
Is the current version incomplete? Or were these errors not supposed to occur? |
I got the build back by replacing
|
Also: the Running @zewa666's sample against the latest version still doesn't work as it should: the dependencies are still ignored when the component tester is re-initialized without ignored dependencies. |
@RomkeVdMeulen I'm still trying to figure out what went wrong in requirejs setup. It's not any easier to debug than webpack. Also in requirejs things are not resolved to their absolute url like webpack, so it's another layer that needs to be accounted. |
There are a number of cache layers in combination of requirejs + default loader + templating. I have not been able to successfully work out how to invalidate cache of all layers for each test. I've reverted the latest code so that if anyone who uses webpack can easily use my branch and build it. |
@bigopon Is there perhaps someone we could pull in on this who is more in-depth on the caching layers? I also wonder wether this will work for Aurelia 2. |
V2 will not, if never, suffer any issue like this, that im pretty confident about. @fkleuver has done an amazing job to ensure apps are properly containerized. How is my branch going for you? |
Working fine with System loader. \EDIT: And using absolute module paths (with an alias in my case). Since that seems to be an issue. |
This adds ability to discard dependencies loading, per
ComponentTester
instance. What it does under the hood:loadTemplate
method on those loadersload
ofHtmlBehaviorResource
to reset the view factory so it should always load fresh, instead of using the cache one.load
above on component disposal.Supersedes #88
closes #88
closes #87
closes #20
@RomkeVdMeulen Can you try this branch and see if it works for your app? I didn't have very thorough test suit. Only accounted a few tests for:
<require from="..."/>
<compose view-model="..."></compose>
<compose view="... .html"></compose>
Usage:
Also added a static method
inView
forStageComponent
class, it was a bit unnecessarily limited to havewithResources()
only, imo.cc @fkleuver @zewa666 @EisenbergEffect